l = [1, 2, 3, 4]
l1 = l[0: 3]    # [1, 2, 3]
l2 = l[1: 3]    # [2, 3]
l3 = l[:]       # [1, 2, 3, 4]
l4 = l[:3]      # [1, 2, 3]


print(r'*' * 100)

dict1 = {'a': 1, 'b': 2, 'c': 3}
for i in l:
    print('index=%s' % i)
for k in dict1:
    print('k=%s , value=%s' % (k, dict1.get(k)))
for k, v in dict1.items():
    print('k=%s , value=%s' % (k, v))
from collections import Iterable
print('判断是否是可迭代的', (isinstance(l, Iterable)))   # True
print('判断是否是可迭代的', (isinstance('abc', Iterable)))   # True
print('判断是否是可迭代的', (isinstance(1, Iterable)))   # False

# index= 0, value= 1 index= 1, value= 2 index= 2, value= 3 index= 3, value= 4
for index, value in enumerate(l):
    print('index= %s, value= %s' % (index, value), end=" ")


print(r'*' * 100)


l = [m + n for m in 'ABC' for n in 'DEF']
print('生成全排列', l)


import os


dirs = [d for d in os.listdir('.')]
print('当前目录下文件：', dirs)



print(r'*' * 100)


l2 = (x for x in range(10))
print(next(l2), next(l2), next(l2))
for item in l2:
    print('item=%s' % item, end=',')


def fib(m):
    n, a, b = 0, 0, 1
    while n < m:
        yield b
        b, a = a+b, b
        n = n+1

f= fib(5)
for n in f:
    print('n=%s' % n, end=',')

g = fib(6)
while True:
    try:
        print('next=%s' % next(g))
    except StopIteration as e:
        print('catch Exception')
        break


print(r'=' * 100)
from collections import Iterator


it = [x for x in range(10)]
print(isinstance(it, Iterable))
print(isinstance(it, Iterator))

for i in it:
    print('i=%s' % i, end = ' ')

itb = iter(it)
print(" ")
print(isinstance(itb, Iterable))
print(isinstance(itb, Iterator))
for i in itb:
    print('it=%s' % i, end = ' ')